import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'

import {localTime} from '../../utils/date'
import './content.scss'

class Content extends Component{
  handleToDetail(item){
    Taro.navigateTo({url: '/pages/detail/index?topicid=' + item.id})
  }
  render(){
    let {title, listData} = this.props
    return(
      <View className='topic-name'>
        <View className='topic-name-title'>{title}</View>
        <View className='topic-name-list'>
          {
            listData.map(item => {
              return (
                <View key={item.id} className='topic-single' onClick={this.handleToDetail.bind(this, item)}>
                  <Image className='topic-single-img' src={item.author.avatar_url} />
                  <Text className='title'>{item.title}</Text>
                  <Text className='topic-single-time'>{localTime(item.last_reply_at)}</Text>
                </View>
              )
            })
          }
        </View>
      </View>
    )
  }
}

export default Content